/*
 * CdnTree.h
 *
 *  Created on: Apr 22, 2013
 *      Author: root
 */

#ifndef CDNTREE_H_
#define CDNTREE_H_

#include "CdnRoom.h"
#include "CdnServerNode.h"
#include "link_list.h"
#include "hash_link_table.h"
#include "utils.h"
/**
 * CdnTree class
 */
class CdnTree {
public:
	CdnTree();
	virtual ~CdnTree();
	int init();

	/**
	 * CreateCdnTree  by xml tree
	 */
    int CreateCdnTree(const char * xmltree);

protected:
    /*
     * struct cdn tree
     */
    int StructCdnTree(TiXmlElement * pXmlNode,CdnArea * pCdnNode);

    /*
	*add svr node to hask table
	*if false,and auto free node
	*/
	bool store_server_node(CdnServerNode * pNode);


	/**
	 * find server node by name
	 */
	CdnServerNode * find_server_node(const char * name);

	/*
	*remove node
	*/
	int remove_server_node(const char * name);

private:
	/*task hash table list,only for find quick*/
	hash_link_table<CdnServerNode> svr_node_table;
	link_list<CdnServerNode> svr_node_list;
	smart_lock  svr_node_lock;
	CdnArea  root;
	bool     create_flag;

};

#endif /* CDNTREE_H_ */
